
layui.use(['form', 'admin', 'ax','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var fs = layui.formSelects;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    fs.on('dag', function(id, vals, val, isAdd, isDisabled){
        var values = val.value.split("/");
        if(values.length == 2) {
            $("#ssdasid").val(values[0]);
            $("#ssdagid").val(values[1]);

            //获取最大的编号
            var ajax = new $ax(Feng.ctxPath + "/archiveLayer/getMaxCode?ssdasid="+values[0]+"&ssdagid="+values[1], function (data) {
                form.val('archiveLayerForm', {xh:data.data});
            }, function (data) {
                Feng.error("获取最大编号失败!");
            });
            ajax.start();
            return true;
        }
        Feng.error("数据不全，无法选取");
        //如果return false, 那么将取消本次操作
        return false;
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/archiveLayer/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/archiveLayer'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/archiveLayer'
    });

});